public class ActivitiesClient extends BaseClient {

	public ActivitiesClient(AtomService atomService) {
		super(atomService);
	}  
 
	public BluehouseService getActivityService() {
		atomService.setResponseType('service');
		return makeServiceCall('/activities/service/atom2/service');
	} 
	 
	/** 
	 * @return List of Activity objects representing most recent 30 public activities
	 */
	public List<ActivityNode> getAllActivities() {
		return getNodes('/activities/service/atom2/activities','');
	} 
	
	public Feed getActivitiesFeed() {
		atomService.setResponseType('feed');
		return getFeed('/activities/service/atom2/activities');
	}
	 
	/**
	 * @return List of Activity objects
	 */
	public List<ActivityNode> getMyActivities() {
		return getNodes('/activities/service/atom2/activities','');
	}
	
	/**
	 * It is only possible to search entries of which you are a member. 
	 * Therfore the results returned from the searching using an email address, will be Activities that 
	 * both you and other person are both members of
	 * @param email
	 * @return
	 */ 
	public List<ActivityNode> getActivitiesByEmail(String email) {
		System.debug('Getting activities by email.');
		System.debug('Atom Service is: ' + getAtomService());
		return getNodes('/activities/service/atom2/activities?public=yes&email='+email,email);
	}
	
	public List<ActivityNode> getActivitiesBySearch(String searchText) {
		System.debug('Getting activities by email.');
		System.debug('Atom Service is: ' + getAtomService());
		return getNodes('/activities/service/atom2/activities?public=yes&search='+searchText,searchText);
	}

	public List<ToDoEntry> getToDos(String activityUuid) {
		System.debug(LoggingLevel.INFO, '\n\n\t GetFeedByUuid: ' + activityUuid + '\n');
		Feed activityFeed = getActivityByUuid(activityUuid);
		System.debug(LoggingLevel.INFO, '\n\n\t getToDos from feed: ' + activityFeed + '\n');
		
		List<ToDoEntry> ret = new List<ToDoEntry>();
		for (AtomBase e : activityFeed.getEntries()) {
			System.debug(LoggingLevel.WARN, '\n\n\t TODO ENTRY: \n' + e.toAPP());
			ret.add( new ToDoEntry(e) );
		}
		return ret; 
	} 
	
	public List<ActivityNode> getActivitiesByUuid(String activityUuid) {
		System.debug('Getting activities by Uuid.');
		System.debug('Atom Service is: ' + getAtomService());
		return getNodes('/activities/service/atom2/activity?activityUuid=' + activityUuid, null);
	}

	public Feed getActivityByUuid(String activityUuid) {
		System.debug(LoggingLevel.INFO, '\n\n\t GetFeedByUuid (in the function): ' + activityUuid + '\n');
		atomService.setResponseType('feed');
		return getFeed('/activities/service/atom2/activity?activityUuid=' + activityUuid);
	}
	
	public Feed getActivityByFQUri(String path) {
		AtomService atomsvc = getAtomService();
		System.debug(LoggingLevel.INFO, '\n\n START URL: ' + path + '\n');
		//path = path.replace(atomsvc.getStartUrl(), '');
		atomService.setResponseType('feed');
		Feed f = getFeed_FQ(path);
		return f;
	}

    public List<ActivityNode> getActivitiesByEmail(List<String> emailList) {
		return getNodesByParameter('/activities/service/atom2/activities?public=yes&email=', emailList);
	}
	
	public List<ActivityNode> getActivitiesByTag(String tag) {
		return getNodes('/activities/service/atom2/activities?public=yes&tag='+tag, tag);
	}
	
    public List<ActivityNode> getActivitiesByTag(List<String> tagList) {
		return getNodesByParameter('/activities/service/atom2/activities?public=yes&tag=', tagList);
	}
	
    public List<ActivityNode> getActivityNodes(String activityUuid) {
		//return getActivityNodesBase('/activities/service/atom2/activities');
    	return getActivityNodesBase('/activities/service/atom2/descendants?nodeUuid=' + activityUuid + '&nodetype=todo');
		//return getActivityNodesBase('/activities/service/atom2/activitynode?activityNodeUuid=DD9G0A0503010D6DD2532DD042A6DC0000E7');
	} 

	public ToDoEntry createTodoItem(ToDoEntry todo, String activityId) {
		Feed act = getActivityByUuid(activityId);
		//System.debug(LoggingLevel.INFO, '\n\nList of activities from CreateToDoItem: ' + acts + '\n');
		todo.addCategory('http://www.ibm.com/xmlns/prod/sn/type', 'todo', 'To Do');
		atomService.setResponseType('todo');
		todo = (ToDoEntry)createActivityNode('/activities/service/atom2/activity?activityUuid=' + activityId, todo);
		return todo;
	} 

	public ToDoEntry createTodoItem(ActivityEntry act) {
		ToDoEntry node = new ToDoEntry();
		String activityCollectionUrl = act.getActivityNodesUrl();
		node.setTitle('ToDo Item?');
		node.addCategory('http://www.ibm.com/xmlns/prod/sn/type', 'todo', 'To Do');
		atomService.setResponseType('todo');
		node = (ToDoEntry)createActivityNode(activityCollectionUrl, node);
		return node;
	}
	
	public ActivityEntry createActivity(ActivityEntry activity) {
		atomService.setResponseType('entry');
		return (ActivityEntry)createActivityEntry('/activities/service/atom2/activities', activity);
	}

	public ActivityEntry createActivity(String title){
		atomService.setResponseType('entry');
		return createActivityEntry('/activities/service/atom2/activities', title);
	}

}